#!/usr/bin/python
# -*-coding:utf-8-*-
import numpy as np

def one_hot(vector, num_classes=None):
    assert isinstance(vector, np.ndarray)
    assert vector.shape[0] > 0
    vector = vector.astype(np.int64)

    if num_classes is None:
        num_classes = int(np.max(vector) + 1)
    else:
        assert num_classes > 0
        assert num_classes >= np.max(vector)

    result = np.zeros(shape=(vector.shape[0], num_classes))
    result[np.arange(vector.shape[0]), vector] = 1

    return result.astype(np.int64)